package com.lineage.server.command.executor;

import com.lineage.server.datatables.ItemTable;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1DwarfInventory;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.templates.L1Item;
import java.util.StringTokenizer;
import java.util.logging.Logger;

public class L1LevelPresent implements L1CommandExecutor {
  private static Logger _log = Logger.getLogger(L1LevelPresent.class.getName());
  
  public static L1CommandExecutor getInstance() {
    return new L1LevelPresent();
  }
  
  public void execute(L1PcInstance pc, String cmdName, String arg) {
    try {
      StringTokenizer st = new StringTokenizer(arg);
      int minlvl = Integer.parseInt(st.nextToken(), 10);
      int maxlvl = Integer.parseInt(st.nextToken(), 10);
      int itemid = Integer.parseInt(st.nextToken(), 10);
      int count = Integer.parseInt(st.nextToken(), 10);
      L1Item temp = ItemTable.get().getTemplate(itemid);
      if (temp == null) {
        pc.sendPackets((ServerBasePacket)new S_SystemMessage("不存在的道具编号。"));
        return;
      } 
      L1DwarfInventory.present(minlvl, maxlvl, itemid, count);
      pc.sendPackets((ServerBasePacket)new S_SystemMessage(
            String.valueOf(String.valueOf(temp.getName())) + "数量" + count + "个发送出去了。(Lv" + minlvl + "~" + maxlvl + ")"));
    } catch (Exception e) {
      pc.sendPackets((ServerBasePacket)new S_SystemMessage(".等级送礼 minlvl maxlvl 道具编号  数量  请输入。"));
    } 
  }
}
